
package com.work.mvc.view.login;

import com.vaadin.ui.*;
import com.vaadin.ui.themes.Reindeer;
import com.work.constants.view.*;
import com.work.i18n.Messages;
import com.work.mvc.controler.LoginControler;

public class LoginWindow extends Window {

	private static final long serialVersionUID = -6845974185241816469L;

	private LoginControler controler = new LoginControler(this);

	private GridLayout mainLayout = new GridLayout(4, 3);
	private Label usernameLabel = new Label(Messages.get("LoginWindow.username"));
	private Label passwordLabel = new Label(Messages.get("LoginWindow.password"));
	private TextField usernameField = new TextField();
	private PasswordField passwordField = new PasswordField();
	private Button logginButton = new Button(Messages.get("Button.login"));

	public LoginWindow()
	{
		super(Messages.get("MainWindow.logging"));
		init();
		addComponents();
	}

	private void init()
	{
		this.setStyleName(Reindeer.WINDOW_BLACK);
		this.setWidth(ComponentsSize.LOGIN_WINDOW_WIDTH);
		this.setHeight(ComponentsSize.LOGIN_WINDOW_HEIGHT);
		this.setClosable(false);
		this.setResizable(false);
		this.setDraggable(false);
		this.center();
	}

	private void addComponents()
	{
		logginButton.addClickListener(controler);
		logginButton.setIcon(ComponentsSources.ICON_LOGIN);

		usernameField.setWidth(ComponentsSize.FULL);
		passwordField.setWidth(ComponentsSize.FULL);

		mainLayout.setSizeFull();
		mainLayout.addComponent(usernameLabel, 1, 0);
		mainLayout.addComponent(usernameField, 2, 0);
		mainLayout.addComponent(passwordLabel, 1, 1);
		mainLayout.addComponent(passwordField, 2, 1);
		mainLayout.addComponent(logginButton, 2, 2);

		mainLayout.setComponentAlignment(usernameLabel, Alignment.BOTTOM_CENTER);
		mainLayout.setComponentAlignment(usernameField, Alignment.BOTTOM_LEFT);
		mainLayout.setComponentAlignment(passwordLabel, Alignment.MIDDLE_CENTER);
		mainLayout.setComponentAlignment(passwordField, Alignment.MIDDLE_LEFT);
		mainLayout.setComponentAlignment(logginButton, Alignment.TOP_LEFT);

		this.setContent(mainLayout);
	}
	
	public String getUsernameValue() {
		return usernameField.getValue();
	}
	
	public String getPasswordValue() {
		return passwordField.getValue();
	}
}
